# 13. 除自身以外数组的乘积.py
from typing import List
class Solution:
    def productExceptSelf(self, nums: List[int]) -> List[int]:
        n = len(nums)
        L_Array = list([1])
        R_Array = list([1])
        L_item, R_item = 1, 1
        # 初始化构造前缀数值和后缀数组
        for i in range(0, n-1):
            L_item = L_item * nums[i]
            R_item = R_item * nums[n-1-i]
            L_Array.append(L_item)
            R_Array.append(R_item)
        R_Array.reverse()
        # test
        # print(L_Array)
        # print(R_Array)
        # 构造答案数组
        ans_List = list()
        for i in range(n):
            ans = L_Array[i] * R_Array[i]
            ans_List.append(ans)
        return ans_List


if __name__ == '__main__':
    solution = Solution()
    example = [1, 2, 3, 4]
    print(example)
    ans = solution.productExceptSelf(example)
    print(ans)